How to count objects with inLinks in current module

Hi everyone,
i start dxl script from the command line and try to numerate objects with matching of some conditions and also incomming links from an assigned module going through a link module

I tried to enable the construction of filters with reference to incoming links (with

Filter hasLinks(LinkFilter value,
string linkModName)

), but it does not work in my case. I have not been able to find a solution for counting all objects with incoming links.

Here is my script:
 

pragma runLim,0
string fullModulePath = "path to current module"
string linkModuleName ="path to link module" // ?name or path to the link module?
Module m = read(fullModulePath, displayModule)
m = current()
Object o = null
Link inLink =null
filtering off
level 0
 
for o in m do 
{
 
    // some conditions
     if (((isMember(o."*attributeName01*", "*foo*"))) and 
                (isMember(o."*attributeName02*", "*foo1*"))) then 
                           {
                             //if has the object at least one incomming link from module A (goung through link module B) then accept and count this obeject otherwise decline this object
                            }
}

 


I am pleased of every help

Thank you so much,
Alexander

 


SystemAdmin - Wed May 12 15:52:40 EDT 2010

Re: How to count objects with inLinks in current module
Ben_Sharples - Thu May 13 04:53:15 EDT 2010

Alexander,

are you trying to count those objects in a module that have incoming links? or the total number of incoming links to the module? (given the assumption that there could be multiple in-links to a single object)

Code below should count both:
 

Object o
Module m = current
link lnk
 
int lnk_count = 0
int obj_count = 0
int lnk_total_count = 0
 
for o in m do {
 
   lnk_count = 0
   for lnk in o <- "*" do { // cycles through all incoming links
        lnk_count++
   }
 
   if (lnk_count > 0) obj_count++
   lnk_total_count = lnk_total_count + lnk_count
}
 
 
print "Number of Objects with Links:\t" obj_count "\n"
print "Total Number of Links:\t lnk_total_count "\n"

Re: How to count objects with inLinks in current module
SystemAdmin - Mon May 17 07:42:15 EDT 2010

Ben_Sharples - Thu May 13 04:53:15 EDT 2010

Alexander,

are you trying to count those objects in a module that have incoming links? or the total number of incoming links to the module? (given the assumption that there could be multiple in-links to a single object)

Code below should count both:
 

Object o
Module m = current
link lnk
 
int lnk_count = 0
int obj_count = 0
int lnk_total_count = 0
 
for o in m do {
 
   lnk_count = 0
   for lnk in o <- "*" do { // cycles through all incoming links
        lnk_count++
   }
 
   if (lnk_count > 0) obj_count++
   lnk_total_count = lnk_total_count + lnk_count
}
 
 
print "Number of Objects with Links:\t" obj_count "\n"
print "Total Number of Links:\t lnk_total_count "\n"

Hi,

thanks for the help.
I trying to count all objects in target module that have incoming links from the specific source module. And it does not matter, whether one or several incoming links are exists. All links are described in link module given by complete path, e.g. NameLinkModule
For the future use and additional metrics it will very helpfull to count all incoming links from the specific source module. This is also already solved by your script.

Could it be a solution for counting?

...
Object o
Module m = current
 
String NameLinkModule ="/../../name"
int obj_count = 0
 
 
bool findInLink(Object TargetObject,string linkModuleName)
{
    LinkRef inLink
    bool found = false
    int lnk_count = 0
    
       
        for inLink in (targetObject)<-linkModuleName do // cycles through all incoming links from source module
        {
                lnk_count++
                        if (lnk_count > 0)
                        {
                                found = true
                break
                        }             
                }  
    
    if (!found)
    {
        // Couldn't find the target object.
        return false
    }
    
} // findInLink
 
for o in m do 
{
 
   if (findInLink(o,linkModuleName))
   {
    obj_count++
   } 
   
}
 
 
print "Number of Objects with Links:\t" obj_count "\n"

Re: How to count objects with inLinks in current module
Ben_Sharples - Mon May 17 08:28:08 EDT 2010

code looks OK,

Issues to consider potentially in the future - multiple source modules of the incoming links (using the same link module) - In this case you would want to test against the source module name

Re: How to count objects with inLinks in current module
adevicq - Tue May 18 04:39:00 EDT 2010

Hi,

you can avoid the test:
 

for inLink in (targetObject)<-linkModuleName do
{
    found = true
        break
}  
 
regards

Re: How to count objects with inLinks in current module
Gedinfo - Mon Jun 28 13:30:46 EDT 2010

Ben_Sharples - Thu May 13 04:53:15 EDT 2010

Alexander,

are you trying to count those objects in a module that have incoming links? or the total number of incoming links to the module? (given the assumption that there could be multiple in-links to a single object)

Code below should count both:
 

Object o
Module m = current
link lnk
 
int lnk_count = 0
int obj_count = 0
int lnk_total_count = 0
 
for o in m do {
 
   lnk_count = 0
   for lnk in o <- "*" do { // cycles through all incoming links
        lnk_count++
   }
 
   if (lnk_count > 0) obj_count++
   lnk_total_count = lnk_total_count + lnk_count
}
 
 
print "Number of Objects with Links:\t" obj_count "\n"
print "Total Number of Links:\t lnk_total_count "\n"

I copied this as is, and Doors 9.2 complains:

-E- DXL: <Line:3> incorrect arguments for function (link)
-E- DXL: <Line:3> undeclared variable (lnk)
-E- DXL: <Line:12> incorrect arguments for (do)
-E- DXL: <Line:22> badly formed token (")
-E- DXL: <Line:22> incorrect arguments for (\)
-E- DXL: <Line:22> undeclared variable (n)
-I- DXL: all done with 6 errors and 0 warnings

Re: How to count objects with inLinks in current module
llandale - Mon Jun 28 16:26:43 EDT 2010

Gedinfo - Mon Jun 28 13:30:46 EDT 2010
I copied this as is, and Doors 9.2 complains:

-E- DXL: <Line:3> incorrect arguments for function (link)
-E- DXL: <Line:3> undeclared variable (lnk)
-E- DXL: <Line:12> incorrect arguments for (do)
-E- DXL: <Line:22> badly formed token (")
-E- DXL: <Line:22> incorrect arguments for (\)
-E- DXL: <Line:22> undeclared variable (n)
-I- DXL: all done with 6 errors and 0 warnings

If you cannot fix this sort of problem then I think you should not be dabbling in DXL. In line 3 he needs to capitalize "Link": "Link lnk". That explains the lnk undeclared. In the last line he has an extra " sign before the \n.